$(function () {
    $('#start_datetime').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    });

    $('#end_datetime').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    });

    $('#startTime').val(dateToStr(startTime));
    $('#start_datetime').datetimepicker('setStartDate', dateToStr(startTime));

    $('#finishTime').val(dateToStr(finishTime));
    $('#end_datetime').datetimepicker('setStartDate',dateToStr(finishTime));

    //++++++++++++++++限制开始时间大于当前,结束时间大于开始时间
    $("#startTime").on("change",function(event){
        var strTime=$("#startTime").val();
        var date = new Date(Date.parse(strTime.replace(/-/g, "/")));
        var endTime=new Date(date.setHours(date.getHours()+1));
        var strEndTime=dateToStr(endTime);
        $("#finishTime").val(strEndTime);
        $('#end_datetime').datetimepicker('setStartDate',strEndTime);
    });
});

function dateToStr(date){
    var dd = date.getDate() < 10 ? "0" + date.getDate() : date.getDate().toString();
    var month=date.getMonth()+1;
    var mmm = month<10? "0" +month: month.toString()
    var yyyy = date.getFullYear().toString();
    var hour=date.getHours()<10 ? "0"+date.getHours():date.getHours().toString();
    var min=date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes().toString();
    return yyyy+"-"+mmm+"-"+dd+" "+hour+":"+min;
}
